package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    //分页查询
    List<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    //根据id查询分类
    @Select("select * from category where id = #{id}")
    Category getById(Long id);

    //新增分类
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into category (type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "values (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void addCategory(Category category);


    //启用、禁用分类
    @AutoFill(value = OperationType.UPDATE)
    @Update("update category set status = #{status}, update_time = now() where id = #{id}")
    void updateStatus(Integer status,Long id);

    //编辑分类
    @AutoFill(value = OperationType.UPDATE)
    @Update("update category set name = #{name}, sort = #{sort}, update_time = now(),update_user=#{updateUser} where id = #{id}")
    void updateCategory(Category category);

    //删除分类
    @Delete("delete from category where id = #{id}")
    void delete(Long id);

    //查询分类
    @Select("select * from category where type = #{type}")
    List<Category> getByType(Integer type);

    //查询所有分类
    @Select("select * from category where status=1 order by sort")
    List<Category> getAll();
}
